from flask import Flask, render_template, request, jsonify
from flask_cors import *
from predict import predict_by_list

app = Flask(__name__)
CORS(app, supports_credentials=True)  # 解决跨域问题


@app.route('/mark_email', methods=['POST'])
def mark_email():    # 接受前端数据，并返回标记后的邮件列表
    # 获取前端传递的数据
    # mailbox_address = request.form['mailbox_address']
    emails_json = request.form['emails']
    # print(eval(emails_json))
    emails = eval(emails_json)  # 将json数据拆分开来
    result = predict_by_list(emails)
    # print(mailbox_address)
    data = {
        "msg": "数据已处理",
        "result": result
    }
    return jsonify(data)    # 传回json格式对象


@app.route('/')
def index():    # 用户测试非跨域情况下的操作
    return render_template("test_index.html")


if __name__ == '__main__':
    app.run()
